//
//  ServiceAgreementViewController.m
//  NetMobileLocation
//
//  Created by Mehmet Sinan Şahin on 4/15/12.
//  Copyright (c) 2012 netgis. All rights reserved.
//

#import "ServiceAgreementViewController.h"
#import "NGUtility.h"
#import "MTPopupWindow.h"


@implementation ServiceAgreementViewController

@synthesize forStartup;


#pragma mark - button actions

-(IBAction)accept:(id)sender {
    if (closeCallbackTarget != nil && [closeCallbackTarget respondsToSelector:@selector(aggrementClose:)]) {
        [closeCallbackTarget aggrementClose:TRUE];
    }    
}

-(IBAction)reject:(id)sender {
    if (closeCallbackTarget != nil && [closeCallbackTarget respondsToSelector:@selector(aggrementClose:)]) {
        [closeCallbackTarget aggrementClose:FALSE];
    }
    if (forStartup)
        exit(0);
    else { 
        [self.view removeFromSuperview];
    }
}

- (id)init {
    self = [super init];
    if (self) {
        forStartup = TRUE;
    }
    return self;
}

- (void) setCloseCallbackTarget: (id) target {
    closeCallbackTarget = target;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        nibNameOrNil = [nibNameOrNil stringByAppendingString:@"-ipad"];
    }
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        forStartup = TRUE;
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [MTPopupWindow showWindowWithHTMLFile:@"TermsAndConditions.html" insideView:self.view];
    
    [btnAccept setTitle:TTLocalizedString(@"Accept", @"")];
    [btnReject setTitle:TTLocalizedString(@"Reject", @"")];
    [navItem setTitle:TTLocalizedString(@"Service Aggrement", @"")];

    
    NSString *fileName = [NSString stringWithFormat:@"ServiceAggrement.%@.rtf",[TTCurrentLocale() localeIdentifier]]; 
    NSString *filePath = [[NSBundle mainBundle] pathForAuxiliaryExecutable:fileName];
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:fileURL];
    [webView sizeToFit];
    [webView loadRequest:requestObj];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
